
#include <iostream>

#include <boost/network/protocol/http/client.hpp>
#include <boost/network/uri.hpp>


#include "HTTPGet.hpp"


namespace http = boost::network::http;
namespace uri  = boost::network::uri;

bool HTTPGet::getDocument(std::string url, std::string & documentData)
{
   try {
      http::client client;
      http::client::request request(url);
      
      // DEBUG: Remove me
      /*
      std::cout << "HTTPGet::getDocument ... " 
                << "\nHost: " << static_cast<std::string>(host(request)) 
                << "\nPath: " << static_cast<std::string>(path(request)) 
                << "\nQuery: " << static_cast<std::string>(query(request)) 
                << "\nAnchor: " << static_cast<std::string>(anchor(request)) 
                << "\nProtocol: " << static_cast<std::string>(protocol(request))
                ;
       */        
      // DEBUG: Remove me

      http::client::response response = client.get(request);
      documentData = static_cast<std::string>(body(response));
   } catch (const std::exception &e) {
      return false;
  }
   
   return true;
}